//
//  HMMainViewController.swift
//  Weibo
//
//  Created by mac on 2017/6/4.
//  Copyright © 2017年 mac. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        let hmtabbar = HMTabBar()
        
        hmtabbar.hmDelegate=self
        
        hmtabbar.composeCallBack={ [unowned self] in
            
        print(self)
        }
        
        
        
        
        self.setValue(hmtabbar, forKey: "tabBar")
            
            
        
        
        
        addChilckViewController(childController: HMHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChilckViewController(childController: HMMeViewController(), title: "消息", imageName: "tabbar_message_center")
        addChilckViewController(childController: HMDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChilckViewController(childController: HMMeViewController(), title: "我的", imageName: "tabbar_profile")
        
    }

    
    //重载添加子控件方法
    func addChilckViewController(childController:UIViewController,title:String,imageName:String)
    {
        
        //设置tabbaritem的属性
        //图片
        childController.tabBarItem.image=UIImage(named: imageName)
        //设置图片原始的渲染方法
        childController.tabBarItem.selectedImage=UIImage(named: "\(imageName)_selected")?.withRenderingMode(.alwaysOriginal)
        //设置字体的颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor .orange], for: UIControlState.normal)
        //设置字体的大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 13)], for: UIControlState.normal)
        
        //设置标题->导航标题和标签标题一样
        childController.title=title
        
        //创建导航控制器
        let nav = UINavigationController(rootViewController: childController)
        
        //添加子视图控制器
        addChildViewController(nav)
        
        
        
        
    }
    
 
}

extension HMMainViewController:HMTabBarDelegate{
    
    func composeOperation(){
        
    }
    
}
